<!doctype html>
<html>
    
    <head>
        <meta charset="utf-8">
        <title>
            登录注册
        </title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
        <link rel="stylesheet" href="css/jquery.mobile-1.4.2.min.css" />
        <link rel="stylesheet" type="text/css" href="css/mobiscrollcss/mobiscroll.custom-2.6.2.min.css">
        <link rel="stylesheet" type="text/css" href="css/clicentcss.css">
        <script type="text/javascript" src="js/lib/jquery-2.1.1.min.js">
        </script>
        <script src="js/mobiscroll.custom-2.6.2.min.js">
        </script>
        <script type="text/javascript" src="js/JKLogin.js">
        </script>
        <script type="text/javascript" src="js/JKCheckForm.js">
        </script>
        <script type="text/javascript" src="js/JKFunc.js">
        </script>
        <script type="text/javascript" src="js/JKRegister.js">
        </script>
        <script type="text/javascript" src="js/lib/jquery.mobile-1.4.2.min.js">
        </script>
        <script type="text/javascript">
            // window.onload = function() {

                var isAutoLogin = "false";
                isAutoLogin = localStorage.getItem("isAutoLogin");
                if (isAutoLogin == "true") {
                    var customerId = localStorage.getItem("customerId");
                    if (customerId != null) {
                        window.location.href = "main.html";
                    }
                }
            // }
        </script>
    </head>
    
    <body>
        <div data-role="page" id="page_5_1" data-theme="jk">
            <div data-role="header">
                <h1 class="ui-corner-all">
                    用户登录
                </h1>
            </div>
            <div data-role="content">
                <div style="color:#FFF">
                    <label for="phone51">
                        手机号：
                    </label>
                    <input type="text" id="phone51" name="phone51">
                    <label for="password51">
                        密码：
                    </label>
                    <input type="password" id="password51" name="password51">
                </div>
                <div class="ui-grid-a">
                    <div class="ui-block-a">
                        <input type="checkbox" style=" border-radius: 10px;" id="auto51" onClick="setAutoLogin()">
                        <label for="auto51" style="border:none; text-align:">
                            自动登录
                        </label>
                    </div>
                    <div class="ui-block-b" align="center" style="margin-top:20px">
                        <a href="#page_5_1_1" data-transition="slide" style="color:#FFFFFF">
                            忘记密码
                        </a>
                    </div>
                </div>
                <div class="ui-grid-a">
                    <div class="ui-block-a">
                        <a class="ui-btn ui-corner-all" style="background-color:#94252a" onClick="login()">
                            登录
                        </a>
                    </div>
                    <div class="ui-block-b">
                        <a class="ui-btn ui-corner-all" href="#page_5_2" data-transition="slide"
                        style="background-color:#94252a">
                            注册
                        </a>
                    </div>
                </div>
            </div>
        </div>
        <script type="text/javascript">
            function setAutoLogin(){if($("#auto51").attr("data-cacheval")=="true"){localStorage.setItem("isAutoLogin",false)}else{localStorage.setItem("isAutoLogin",true)}}
            function login(){var txt="";var phone51=$("#phone51").val();var password51=$("#password51").val();if(phone51==""){txt+=" 手机号"}if(password51==""){txt+=" 密码"}if(txt!=""){txt+=" 还未填写";messageBox(txt)}else{JKjsonP({ws:"customer/login",parameter:{telephone:phone51,password:password51},sFunc:function(json){if(json.result=="success"){localStorage.setItem("customerId",json.data.id);localStorage.setItem("customerTelephone",json.data.telephone);if(typeof(mobile) != 'undefined' && !DEBUG) {mobile.login(json.data.telephone);}localStorage.setItem("customerUsername",json.data.username);window.location.href="main.html"}else{messageBox(json.msg)}},eFunc:function(XMLHttpRequest,textStatus,emessage){messageBox("服务器解析数据错误")}})}}
        </script>
        <div data-role="page" id="page_5_2" data-theme="jk">
            <div data-role="header">
                <h1 class="ui-corner-all">
                    用户注册
                </h1>
            </div>
            <div data-role="content">
                <div>
                    <label for="phone52" style="color:#FFFFFF">
                        手机号码：
                    </label>
                    <input type="text" id="phone52" name="phone51">
                    <label for="rphone52" style="color:#FFFFFF">
                        确认手机：
                    </label>
                    <input type="text" id="rphone52" name="rphone51">
                    <label for="password52" style="color:#FFFFFF">
                        密码：
                    </label>
                    <input type="password" id="password52" name="password51">
                    <label for="password52" style="color:#FFFFFF">
                        确认密码：
                    </label>
                    <input type="password" id="rpassword52" name="rpassword51">
                    <label for="nickname52" style="color:#FFFFFF">
                        昵称：
                    </label>
                    <input type="text" id="nickname52" name="nickname51">
                    <div class="ui-grid-b">
                        <div class="ui-block-a" style="margin-top:15px">
                            <label for="vcode51" style="color:#FFFFFF">
                                短信验证码：
                            </label>
                        </div>
                        <div class="ui-block-b">
                            <input type="text" id="vcode51" name="vcode51">
                        </div>
                        <div class="ui-block-c" align="center" style="margin-top:15px">
                            <span>
                                <a href="javascript:void(0)" id="getS3" onClick="getSms('#getS3')" style="color:#FFF">
                                    获取验证码
                                </a>
                            </span>
                        </div>
                    </div>
                </div>
                <div class="ui-grid-a">
                    <div class="ui-block-a">
                        <a class="ui-btn ui-corner-all" onClick="registerCustomer()" style="background-color:#94252a">
                            提交
                        </a>
                    </div>
                    <div class="ui-block-b">
                        <a class="ui-btn ui-corner-all" data-rel="back" data-icon="back" style="background-color:#94252a">
                            返回
                        </a>
                    </div>
                </div>
            </div>
            <div data-role="popup" id="page_5_2_1" data-theme="jk">
                <div align="center">
                    <p style="margin-top:15px">
                        操作成功！
                    </p>
                    <p>
                        <span>
                            手机：
                        </span>
                        <span id="phone521">
                        </span>
                    </p>
                    <div>
                        <span>
                            昵称：
                        </span>
                        <span id="nickname521">
                        </span>
                    </div>
                    <div>
                        <a class="ui-btn ui-shadow ui-corner-all ui-btn-inline ui-btn-mini" href="#page_5_1"
                        data-transition="slide" style="color:#94252a">
                            返回
                        </a>
                    </div>
                </div>
            </div>
            <div data-role="popup" id="page_5_2_2" data-theme="jk" style="height:180px">
                <div align="center">
                    <p style="margin-top:15px" id="error522">
                        操作失败！
                    </p>
                    <br>
                    <div class="ui-grid-a">
                        <div class="ui-block-a">
                            <a class="ui-btn ui-corner-all ui-btn-inline" onClick="" href="#page_5_2"
                            style="color:#94252a">
                                重新执行
                            </a>
                        </div>
                        <div class="ui-block-b">
                            <a class="ui-btn ui-corner-all " href="#page_5_1" style="color:#94252a"
                            data-transition="slide">
                                返回
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <script type="text/javascript">
            function registerCustomer() {
                var txt = "";
                var phone52 = $("#phone52").val(); // 手机号输入对象
                var rphone52 = $("#rphone52").val(); // 二次手机号输入对象
                var password52 = $("#password52").val(); // 密码输入对象
                var rpassword52 = $("#rpassword52").val(); // 二次密码输入对象
                var nickname52 = $("#nickname52").val(); // 用户名输入对象=
                var sms = $('#vcode51').val();
                if (phone52 == "") {
                    txt += "手机号码"
                }
                if (rphone52 == "") {
                    txt += " 确认手机"
                }
                if (password52 == "") {
                    txt += " 密码"
                }
                if (rpassword52 == "") {
                    txt += " 确认密码"
                }
                if (nickname52 == "") {
                    txt += " 昵称"
                }
                if (sms == '') {
                    txt += " 验证码";
                }
                if (txt != "") {
                    txt += " 还未填写";
                    messageBox(txt);
                } else if (JKCheckMobileSet($("#phone52"), $("#rphone52"))) {
                    if (JKCheckPasswordSet($("#password52"), $("#rpassword52"))) {

                        JKjsonP({
                            ws: "merchants/validateSmsCode",
                            parameter: {
                                phoneNumber: phone52,
                                code: sms
                            },
                            sFunc: function(json) {
                                if (json.result == "success") {
                                    JKjsonP({
                                        ws: "customer/registerCustomer",
                                        parameter: {
                                            telephone: phone52,
                                            password: password52,
                                            username: nickname52
                                        },
                                        sFunc: function(json) {
                                            if (json.result == "success") {
                                                $("#phone521").html(phone52);
                                                $("#nickname521").html(nickname52);
                                                $("#page_5_2_1").popup("open");

                                            } else {
                                                $("#error522").html(json.msg);
                                                $("#page_5_2_2").popup("open");
                                            }
                                        },
                                        eFunc: function(XMLHttpRequest, textStatus, emessage) {
                                            messageBox("服务器解析数据错误");
                                        }
                                    });
                                } else {
                                    messageBox(json.msg);
                                }
                            },
                            eFunc: function(XMLHttpRequest, textStatus, emessage) {
                                messageBox("服务器解析数据错误");
                            }
                        });

                    }
                }
            }

            var timeout = 60;
            var interValT;
            function getSms(id) {
                var telephone = '';
                if (id == "#getS1") {
                    telephone = $.trim($('#phone511').val());
                } else if (id == '#getS3') {
                    telephone = $.trim($('#phone52').val());
                }
                if (telephone == '') {
                    messageBox('请填写手机号');
                } else if (telephone.match(/^1[3|4|5|7|8][0-9]\d{8}$/) == null) {
                    messageBox('请输入正确的手机号');
                } else {
                    $(id).attr('onclick','').unbind('click');
                    interValT = setInterval(function() {
                        if (timeout == 0) {
                            timeout = 60;
							
                            $(id).bind('click',
                            function() {
                                getSms(id);
                            }).html('获取验证码');
                            clearInterval(interValT);
                        } else {
                            $(id).html(timeout--+'秒');
                        }
                    },
                    1000);

                    JKjsonP({
                        ws: "merchants/sendSmsCode",
                        parameter: {
                            phoneNumber: telephone
                        },
                        sFunc: function(json) {
                            if (json.result == "success") {} else {
                                messageBox(json.msg);
                            }
                        },
                        eFunc: function(XMLHttpRequest, textStatus, emessage) {
                            messageBox("服务器解析数据错误");
                        }
                    });
                    // messageBox('已发送');
                }
            }
        </script>
        <div data-role="page" id="page_5_1_1" data-theme="jk">
            <div data-role="header">
                <h1 class="ui-corner-all">
                    重设密码
                </h1>
            </div>
            <div data-role="content">
                <div>
                    <label for="phone511" style="color:#FFF">
                        手机号码：
                    </label>
                    <input type="text" id="phone511" name="phone511">
                    <label for="password511" style="color:#FFF">
                        密码：
                    </label>
                    <input type="password" id="password511" name="password511">
                    <label for="password511" style="color:#FFF">
                        确认密码：
                    </label>
                    <input type="password" id="rpassword511" name="rpassword511">
                    <div class="ui-grid-b">
                        <div class="ui-block-a" style="margin-top:15px; width:auto">
                            <label for="vcode511" style="color:#FFF">
                                短信验证码：
                            </label>
                        </div>
                        <div class="ui-block-b">
                            <input type="text" id="vcode511" name="vcode511">
                        </div>
                        <div class="ui-block-c" align="center" style="margin-top:15px">
                            <span>
                                <a href="javascript:void(0)" id="getS1" onClick="getSms('#getS1')" style="color:#FFF">
                                    获取验证码
                                </a>
                            </span>
                        </div>
                    </div>
                </div>
                <div class="ui-grid-a">
                    <div class="ui-block-a">
                        <a class="ui-btn ui-corner-all" onClick="resetPassword()" style="background-color:#94252a">
                            重设
                        </a>
                    </div>
                    <div class="ui-block-b">
                        <a class="ui-btn ui-corner-all" data-rel="back" data-icon="back" style="background-color:#94252a">
                            返回
                        </a>
                    </div>
                </div>
            </div>
        </div>
        <script type="text/javascript">
            function resetPassword() {
                var txt = "";
                var phone511 = $("#phone511").val();
                var password511 = $("#password511").val();
                var rpassword511 = $("#rpassword511").val();
                var sms = $('#vcode511').val();
                if (phone511 == "") {
                    txt += "手机号码"
                }

                if (password511 == "") {
                    txt += " 密码"
                }
                if (rpassword511 == "") {
                    txt += " 确认密码"
                }
                if (sms == "") {
                    txt += "短信验证码"
                }
                if (txt != "") {
                    txt += " 还未填写";
                    messageBox(txt);
                } else if (JKCheckPasswordSet($("#password511"), $("#rpassword511"))) {
                    JKjsonP({
                            ws: "merchants/validateSmsCode",
                            parameter: {
                                phoneNumber: phone511,
                                code: sms
                            },
                            sFunc: function(json) {
                                if (json.result == "success") {
                                    JKjsonP({
                                        ws: "customer/changePassword",
                                        parameter: {
                                            telephone: phone511,
                                            newPassword: password511
                                        },
                                        sFunc: function(json) {
                                            if (json.result == "success") {
                                                messageBox("重置成功！");
                                                changePage("#page_5_1");
                                            } else {
                                                messageBox("重置失败，请重新尝试");
                                            }
                                        },
                                        eFunc: function(XMLHttpRequest, textStatus, emessage) {
                                            messageBox("服务器解析数据错误");
                                        }
                                    });
                                } else {
                                    messageBox(json.msg);
                                }
                            },
                            eFunc: function(XMLHttpRequest, textStatus, emessage) {
                                messageBox("服务器解析数据错误");
                            }
                        });

                    
                }
            }
        </script>
    </body>

</html>